enum PIN {
    //% block="P0"
    1,
    //% block="P1"
    2
}

//% color="#ff9f06" iconWidth=50 iconHeight=40
namespace DS18B20 {

    //% block="Read [PIN] results " blockType="command" 
    //% PIN.shadow="dropdown" PIN.options="PIN"
    export function SET_DS18B20(parameter: any, block: any) {
        let pin = parameter.PIN.code

        Generator.addInclude("OneWire", "#include <OneWireL.h>");
        Generator.addInclude("DallasTemperature", "#include <DallasTemperatureL.h>");
        Generator.addObject(`int`, `int`, `oneWireBus = ${pin} ;`);
        Generator.addObject(`OneWire`, `OneWire`, `oneWire(oneWireBus);`);
        Generator.addObject(`DallasTemperature`, `DallasTemperature`, `sensors(&oneWire);`);
        Generator.addSetup(`begin`, `sensors.begin();`)
        Generator.addCode(`sensors.requestTemperatures();`);
        // Generator.addCode(`sensors.getTempCByIndex(0);`);
    }

    //% block="Read [PIN] temperature(℃)" blockType="reporter" 
    //% PIN.shadow="dropdown" PIN.options="PIN"
    export function READ_DS18B20(parameter: any, block: any) {
        Generator.addCode(`sensors.getTempCByIndex(0)`);

    }


}

